$(function () {
    localStorage.clear();
    getInfoDeatails()
    setInterval(function () {
        getInfoDeatails()
    }, 1000)
    getInfoDeatails2222()
    setInterval(function () {
        getInfoDeatails2222()
    }, 1000 * 30)
    $('.popupClose2').on('click', function () {
        $('.popupClose2').css('display', 'none');
        $('.popup2').animate({ width: '3px' }, 400, function () {
            $('.popup2').animate({ height: 0 }, 400);
        });
        setTimeout(summaryHide2, 800);
    });


})





function getInfoDeatails() {
   
    $.ajax(baseUrl + ":8091/dev-device-instance/getDeviceDataInfo", {
        method: 'GET',
        data: {
            id: "pdjcld",
        },
        headers: {
            "content-type": "application/json",
        },
        success: function (result) {

            if (result.code == 200) {
          
                document.getElementById("num3").innerHTML = result.data.list.records[0].Tag2
                document.getElementById("num4").innerHTML = result.data.list.records[0].Tag1
          
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}

function addldinfo(val){
    let dapa={
        ldPa:val
    }
    $.ajax("http://192.168.15.10:8080/yewu/info/addLdTableInfo", {
        method: 'POST',
        data: JSON.stringify(dapa),
        headers: {
            "content-type": "application/json",
        },
        success: function (result) {
            if (result.code == 200) {
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}

function getInfoDeatails2222() {
    
    $.ajax(baseUrl + ":8091/dev-device-instance/getDeviceDataInfo", {
        method: 'GET',
        data: {
            id: "pdjcld",
        },
        headers: {
            "content-type": "application/json",
        },
        success: function (result) {

            if (result.code == 200) {
          
         
                addldinfo(result.data.list.records[0]);
            }
        },
        error: function (err) {
            console.log(err);
        }
    })

    

}

function summaryHide2() {
    localStorage.clear()
    $('.filterbg2').hide();
    $('.popup2').hide();
    $('.popup2').width(0);
};

function cliclCommonImgld() {
    var clickIndex = localStorage.getItem("clickIndex");
    if (clickIndex == 2) {
        return
    }
    if (clickIndex) {
        $('.popupClose' + clickIndex).css('display', 'none');
        $('.popup' + clickIndex).animate({ width: '3px' }, 400, function () {
            $('.popup' + clickIndex).animate({ height: 0 }, 400);
        });
        setTimeout(function () {
            $('.filterbg' + clickIndex).hide();
            $('.popup' + clickIndex).hide();
            $('.popup' + clickIndex).width(0);
            localStorage.setItem("clickIndex", "2");
        }, 400);
    } else {
        localStorage.setItem("clickIndex", "2");
    }


    $('.filterbg2').show();
    $('.popup2').show();
    $('.popup2').width('3px');
    $('.popup2').animate({ height: '56%' }, 400, function () {
        $('.popup2').animate({ width: '50%' }, 400);
    });
    setTimeout(summaryShow2, 800);
}
function summaryShow2() {

    $('.popupClose2').css('display', 'block');
    getAlarmData2()
    getMainChartWeatherData()
    setInterval(function () {
        getMainChartWeatherData()
    }, 1000 * 30)
    getWarnInfoData()

};


function getAlarmData2() {
    $.ajax("http://192.168.15.10:8080/store/info/getSoteInfolaster", {
        method: 'GET',
        headers: {
            "content-type": "application/json",
        },
        success: function (result) {
            if (result.code == 200) {
                document.getElementById("weatherobsTime").innerHTML = formattedDate(result.data.obsTime)
                document.getElementById("weatherairf").innerHTML = "AQI(空气质量指数)：" + result.data.aqi + "μg/m3，" + formattedAqi(result.data.aqi)
                document.getElementById("wenduId").src = './images/' + result.data.icon + ".png"
                document.getElementById("currentWendu").innerHTML = result.data.temp + "℃"
                document.getElementById("currentWenduText").innerHTML = result.data.text

                $("#commonfoot1").text(result.data.windScale + "级");
                $("#commonfoot1_1").text(result.data.windDir);

                $("#commonfoot2").text(result.data.humidity + "%");
                $("#commonfoot3").text(result.data.feelsLike + "℃")
                $("#commonfoot4").text(result.data.vis + "km")
                $("#commonfoot5").text(result.data.precip + "mm")
                $("#commonfoot6").text(result.data.pressure + "hPa")
            }

        },
        error: function (err) {
            console.log(err);
        }
    })

}


function getMainChartWeatherData() {

    $.ajax("http://192.168.15.10:8080/yewu/info/getCurrentDataInfo2", {
        method: 'GET',
        headers: {
            "content-type": "application/json",
        },
        success: function (result) {
            if (result.code == 200) {

                getMainChartWeather(result.data)

            }

        },
        error: function (err) {
            console.log(err);
        }
    })

}


//diaMainChartWeather
function getMainChartWeather(list) {
    var id = [];
    var timeArr = []
    var ldjzArr = []
    var ldqdArr = []

    for (let i = 0; i < list.length; i++) {
        //判断在id这个数组中有没有找到id
        if (id.indexOf(getNowFormatDate(list[i].create_time)) == -1) {
            //把id用push存进id这个数组中
            id.push(getNowFormatDate(list[i].create_time));
            // timeArr.push(str[i]);
            timeArr.push(getNowFormatDate(list[i].create_time))
            ldjzArr.push(list[i].Tag1)
            ldqdArr.push(list[i].Tag2)
        }
    }
    var chartDom = document.getElementById('diaMainChartWeather');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
        title: {
            text: ''
        },
        tooltip: {
            trigger: 'axis'
        },
        color: ['aqua', 'red'],
        legend: {
            data: ['雷电均值', '雷电强度'],
            textStyle: {
                color: "#fff"
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {},
        xAxis: {
            type: 'category',
            // boundaryGap: false,
            data: timeArr,


            axisLabel: {
                show: true,//是否显示轴线
                textStyle: {
                    color: '#fff' // 设置x轴字体颜色为红色
                },
                lineStyle: {
                    color: '#fff',//刻度线的颜色
                    width: 2
                }

            },
        },
        yAxis: {
            name: "KV/m", //y轴上方的单位
            type: 'value',
            axisLine: {
                show: true,//是否显示轴线
                lineStyle: {
                    color: '#fff',//刻度线的颜色
                    width: 2
                }
            },
        },
        series: [
            {
                name: '雷电均值',
                type: 'line',
                // stack: 'Total',
                data: ldjzArr
            },
            {
                name: '雷电强度',
                type: 'line',
                // stack: 'Total',
                data: ldqdArr
            }
        ]
    };

    option && myChart.setOption(option);
}


function getWarnInfoData() {
    //getWarnInfolaster
    $.ajax("http://192.168.15.10:8080/warn/info/getWarnInfolaster", {
        method: 'GET',
        headers: {
            "content-type": "application/json",
        },
        success: function (result) {
            if (result.code == 200) {
                if (result.data) {
                    $("#warningnoData").css("display", "none");
                    $("#warningyesData").css("display", "block");
                    $("#diaright_1").text(result.data.title);
                    $("#diaright_2").text(result.data.typeName + "：" + result.data.text);
                    $("#diaright_3").text("开始时间：" + formattedDate(result.data.startTime));
                    $("#diaright_4").text("结束时间：" + formattedDate(result.data.endTime));
                } else {
                    $("#warningnoData").css("display", "block");
                    $("#warningyesData").css("display", "none");
                    $("#diaright_1").text("");
                    $("#diaright_2").text("");
                    $("#diaright_3").text("");
                    $("#diaright_4").text("");
                }
            }

        },
        error: function (err) {
            console.log(err);
        }
    })
}